﻿using Engine;
using Engine.Graphics;

namespace Game {
    public class RCEntryButton : BevelledButtonWidget {
        public RCEntryButton() {
            Size = new Vector2(60, 60);
            BevelColor = new Color(54, 54, 54);
            CenterColor = new Color(54, 54, 54);
            RectangleWidget rectangle = new() {
                Size = new Vector2(40, 40),
                TextureLinearFilter = true,
                HorizontalAlignment = WidgetAlignment.Center,
                VerticalAlignment = WidgetAlignment.Center,
                Subtexture = ContentManager.Get<Subtexture>("RCTextures/Gui/RuthlessConquestTransparentIcon"),
                OutlineColor = Color.Transparent,
                FillColor = Color.White,
                IsVisible = true,
                TextureAnisotropicFilter = true,
                BlendState = BlendState.NonPremultiplied
            };
            AddChildren(rectangle);
        }

        public override void Update() {
            if (IsClicked) {
                if (ScreensManager.FindScreen<RuthlessConquest.MainMenuScreen>("RCMainMenu") == null) {
                    InitializeRC();
                }
                ScreensManager.SwitchScreen("RCMainMenu");
            }
        }

        public static void InitializeRC() {
            //RuthlessConquest.SettingsManager.Initialize();
            RuthlessConquest.AnalyticsManager.Initialize();
            RuthlessConquest.VersionsManager.Initialize();
            RuthlessConquest.Colors.InitializeColorScheme();
            ScreensManager.AddScreen("RCMainMenu", new RuthlessConquest.MainMenuScreen());
            ScreensManager.AddScreen("RCSettings", new RuthlessConquest.SettingsScreen());
            ScreensManager.AddScreen("RCModSettings", new RuthlessConquest.ModSettingsScreen());
            ScreensManager.AddScreen("RCCredits", new RuthlessConquest.CreditsScreen());
            ScreensManager.AddScreen("RCGameList", new RuthlessConquest.GameListScreen());
            ScreensManager.AddScreen("RCPracticeSetup", new RuthlessConquest.PracticeSetupScreen());
            ScreensManager.AddScreen("RCGameSetup", new RuthlessConquest.GameSetupScreen());
            ScreensManager.AddScreen("RCGame", new RuthlessConquest.GameScreen());
            MusicManager.StopMusic();
            MusicManager.CurrentMix = MusicManager.Mix.InGame;
            Window.m_view.Update += UpdateRC;
        }

        public static void UpdateRC(double dt) {
            RuthlessConquest.ServersManager.Update();
        }
    }
}